// 定义全局接口地址
var g_api = "https://xinxigang-jy-end.hzdctech.com/v1/";
//定义全局学生列表和班级列表
//班级列表
var classListTags = '';
$.ajax({
    type: "post",
    url: g_api + 'teamList',
    contentType: "application/json",
    dataType: "json",
    async: false,
    success: function (res) {
        // console.log(res)
        if (res.code == 0) {
            classListTags = res.datas.team_list;
        }
    }
});
$("#sun_class_select_one").append("<option selected='selected' disabled='disabled' style='display: none' value=''></option>");
// console.log(classListTags)
if (classListTags) {
    $.each(classListTags, function (k, v) {  // forEach遍历大数组
        $("#sun_class_select_one").append('<option value="' + classListTags[k].classno + '">' + classListTags[k].classno + '</option>');
    });
}
$("#sun_class_select_one").selectpicker('refresh');
$('#sun_class_select_one').on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
    if (isSelected) {
        $('#sun_students_select_one').empty();
        var classno = $(this).val();
        // 字符串去除分隔符“,”再转换为数组
        var valData = [];
        $.ajax({
            type: "post",
            url: g_api + 'studentList',
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify({classno: classno}),
            async: false,
            success: function (res) {
                console.log(res)
                if (res.code == 0) {
                    studentsListTags = res.datas.student_list;
                }
            }
        });
        $("#sun_students_select_one").append("<option selected='selected' disabled='disabled' style='display: none' value=''></option>");
        // console.log(classListTags)
        if (studentsListTags) {
            $.each(studentsListTags, function (k, v) {  // forEach遍历大数组
                $("#sun_students_select_one").append('<option value="' + studentsListTags[k].userid + '">' + studentsListTags[k].username + '</option>');
            });
        }
        $('.sun-students-select-one').selectpicker({noneSelectedText: '学生列表'});
        //多选回填数据时赋值，valData是回显数据的值，是一个数组
        $("#sun_students_select_one").selectpicker("val", valData)
        $("#sun_students_select_one").selectpicker('refresh');
    }

})
var studentsSelected = [];
$("#sun_students_select_one").change(function () {
    // console.log($("#sun_students_select_one").val());
    $("#students_id_arr").val($("#sun_students_select_one").val());
    studentsSelected = $("#students_id_arr").val().split(",");
    console.log(studentsSelected)
    $('.sun-students-select-one .dropdown-menu').show()
    // if(studentsSelected.length == 6){
    // $('.sun-students-select-one .dropdown-menu').hide();//当选择六个学生后关闭选择框并执行函数动作
    $.ajax({
        type: "post",
        url: g_api + 'getCateUsageChartByStudents',
        contentType: "application/json",
        dataType: "json",
        data: JSON.stringify({'student_id_arr': studentsSelected}),
        async: false,
        success: function (res) {
            // console.log(res)
            if (res.code == 0) {
                if (res.datas.length > 0) {
                    var data = res.datas.user_cate_usage;
                    // loadStudentsList(data)
                }

                // $('.sun-students-select-one .dropdown-menu').hide();
                // studentsListTags = res.datas.student_list;
            }
        }
    });
    // loadStudentsList()
    // }
})

// $('#sun_class_select_one').on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
// 	console.log(previousValue)
// })

// $('#sun_class_select_one').append(classListTagsHtml);

// console.log(classListTags);
//全局渠道信息
var g_channelInfo = {};

//渠道报告内容建议说明
function channelReportContent(rePortData) {
    var reportContent = "很抱歉，目前暂无可分析的数据";
    if (undefined != rePortData.channelAvgTime && "" != rePortData.channelAvgTime) {
        if (rePortData.channelAvgTime > 20) {
            if (rePortData.popval <= 0.3) {
                reportContent = "业绩很棒，受理偏慢，请适当加快受理";
            } else {
                reportContent = "受理速度偏慢，影响客户感知，请加强受理技能培训";
            }
        } else {
            //判断厅是否有排队机
            if (rePortData.lineUpData.length > 0) {
                var callTime = rePortData.lineUpData[rePortData.lineUpData.length - 1];
                var t1 = rePortData.channelAvgTime - callTime;
                if (t1 >= 3) {
                    if (rePortData.popval <= 0.3) {
                        reportContent = "门店运营良好，可适当提升受理速度";
                    } else {
                        reportContent = "门店运营良好，建议加强营销";
                    }
                } else if (callTime > rePortData.channelAvgTime) {
                    reportContent = "门店台席规划不合理，存在客户积压，请按业务类型分流";
                } else if (0 <= t1 && t1 < 3) {
                    if (rePortData.popval <= 0.3) {
                        reportContent = "门店运营状态良好，台席规划合理，请继续保持";
                    } else {
                        reportContent = "台席规划合理，建议适当加强营销";
                    }
                }
            } else {
                var custNum = rePortData.custNumData[rePortData.custNumData.length - 1] || 0;
                if (custNum <= 50) {
                    if (rePortData.popval <= 0.3) {
                        reportContent = "营业效能规划合理，厅内客流量仍有上升空间";
                    } else {
                        reportContent = "客流较小，请加强营销手段";
                    }
                } else {
                    if (rePortData.popval <= 0.3) {
                        reportContent = "厅店客流量大，营业效能规划合理，请继续保持";
                    } else {
                        reportContent = "厅店客流量大，请把握机会加强营销";
                    }
                }
            }
        }
    }
    $(".analysis-info").text(reportContent);
}

//加载营业员受理详情
function loadStaffHandleDetail(data) {
    //获取员工违规信息
    var staffWgInfo = data.staffWgInfo;
    //获取员工积分信息
    var channelJfMap = data.channelJfMap;
    var channelStaffLen = data.channelStaffLen;
    var staffHandleInfo = data.staffHandleInfo || [], staffHandleInfoLen = staffHandleInfo.length;
    var html = [], index = 0;
    for (var key in staffHandleInfo) {
        var itemArr = staffHandleInfo[key];
        index++;
        var indexClass = (1 == index) ? "first" : "";
        var wgCount = staffWgInfo[itemArr[0].staffCode] || "0";
        var tr1 = [
            '<tr class="td-avg-time">',
            '<td colspan="3">',
            '<div class="index ' + indexClass + '">' + itemArr[0].index + '</div>',
            '<div class="staff-name">' + itemArr[0].staffName + '</div>',
            '<div class="avg-time-label">|&nbsp;&nbsp;厅排名</div>',
            '<div class="avg-time-value">' + itemArr[0].index + '/' + channelStaffLen + '</div>',
            '</td>',
            '</tr>',
            '<tr>',
            '<td> ',
            '<div class="staff-cust-time">',
            '<span style="font-size:15px;">订单耗时</span><br/><span style="color:#00A8FE;font-size:18px;font-weight:600;">' + itemArr[0].avgTime + '分</span>',
            '</div>',
            '</td>',
            '<td>',
            '<div class="staff-order-count">',
            '<span style="font-size:15px;">订单量</span><br/><span style="color:#00A8FE;font-size:18px;font-weight:600;">' + itemArr[0].orderNum + '笔</span>',
            '</div>',
            '</td>',
            '<td>',
            '<div class="staff-alarm">',
            '<span style="font-size:15px;">违规告警</span><br/><span style="color:#00A8FE;font-size:18px;font-weight:600;">' + wgCount + '次</span>',
            '</div>',
            '</td>',
            '</tr> ',
            '<tr class="td-integral"> ',
            '<td colspan="3"> ',
            '<div class="integral-label">个人积分：</div> ',
            '<div class="integral-value">' + (channelJfMap[itemArr[0].staffCode + '_charge'] || 0) + '分</div> ',
            '<div class="integral-label" style="width:60px;">|厅排名</div>',
            '<div class="integral-value" style="width:100px;">' + (channelJfMap[itemArr[0].staffCode + "_index"] || 0) + '/' + (channelJfMap["channelLength"] || 0) + '</div>',
            '</td> ',
            '</tr> ',
        ];
        var tr2 = [];
        if (itemArr.length > 1) {
            index++;
            var indexClass = (2 == index) ? "second" : "";
            var wgCount = staffWgInfo[itemArr[1].staffCode] || "0";
            tr2 = [
                '<tr><td colspan="3"><div class="split-line"></div></td></tr>',
                '<tr class="td-avg-time"> ',
                '<td colspan="3"> ',
                '<div class="index ' + indexClass + '">' + itemArr[1].index + '</div>',
                '<div class="staff-name">' + itemArr[1].staffName + '</div>',
                '<div class="avg-time-label">|&nbsp;&nbsp;厅排名</div>',
                '<div class="avg-time-value">' + itemArr[1].index + '|' + channelStaffLen + '</div>',
                '</td>',
                '</tr>',
                '<tr>',
                '<td> ',
                '<div class="staff-cust-time">',
                '<span style="font-size:15px;">订单耗时</span><br/><span style="color:#00A8FE;font-size:18px;font-weight:600;">' + itemArr[1].avgTime + '分</span>',
                '</div>',
                '</td>',
                '<td>',
                '<div class="staff-order-count">',
                '<span style="font-size:15px;">订单量</span><br/><span style="color:#00A8FE;font-size:18px;font-weight:600;">' + itemArr[1].orderNum + '笔</span>',
                '</div>',
                '</td>',
                '<td>',
                '<div class="staff-alarm">',
                '<span style="font-size:15px;">违规告警</span><br/><span style="color:#00A8FE;font-size:18px;font-weight:600;">' + wgCount + '次</span>',
                '</div>',
                '</td>',
                '</tr> ',
                '<tr class="td-integral"> ',
                '<td colspan="3"> ',
                '<div class="integral-label">个人积分：</div> ',
                '<div class="integral-value">' + (channelJfMap[itemArr[1].staffCode + '_charge'] || 0) + '分</div> ',
                '<div class="integral-label" style="width:60px;">|厅排名</div>',
                '<div class="integral-value" style="width:100px;">' + (channelJfMap[itemArr[1].staffCode + "_index"] || 0) + '/' + (channelJfMap["channelLength"] || 0) + '</div>',
                '</td> ',
                '</tr> ',
            ]
        }
        var staffHtml = [
            '<div class="swiper-slide">',
            '<table>',
            tr1.join(""),
            tr2.join(""),
            '</table>',
            '</div> '
        ];
        html.push(staffHtml.join(""));
    }
    $("#staff-info").html("");
    if (html.length > 0) {
        var dataHtml = "<div class='swiper-container visual_swiper_staffInfo'><div class='swiper-wrapper'>" + html.join("") + "</div>"
        $("#staff-info").html(dataHtml);
        var mySwiper1 = new Swiper('.visual_swiper_staffInfo', {
            autoplay: true,//可选选项，自动滑动
            speed: 1500,//可选选项，滑动速度
            autoplay: {
                delay: 15000,//毫秒
            }
        });
    } else {
        noDataTip($("#staff-info"));
    }
}

//加载门店台席健康度详情
function loadChannelDeviceDetail(data) {
    var html = [];
    //设置台席灯
    $(".device-alarm").eq(2).find("span[type='greenGrade']").text(data.greenGrade || "0");
    $(".device-alarm").eq(1).find("span[type='redGrade']").text(data.redGrade || "0");
    $(".device-alarm").eq(0).find("span[type='grayGrade']").text(data.grayGrade || "0");
    var deviceInfo = data.deviceInfo;
    for (var key in deviceInfo) {
        var itemArr = deviceInfo[key];
        itemArr[0].up = itemArr[0].up || "--";
        itemArr[0].down = itemArr[0].down || "--";
        var gradeImg = "";
        if (1 == itemArr[0].healthGrade) {
            gradeImg = "device-green.png";
        } else if (2 == itemArr[0].healthGrade) {
            gradeImg = "device-red.png";
        } else {
            gradeImg = "device-gray.png";
        }
        var tr1 = [
            '<tr> ',
            '<td rowspan="3" class="device-img">',
            '<img src="../static/images/' + gradeImg + '"/>',
            '</td> ',
            '<td><div class="label-name">台席分数</div></td> ',
            '<td rowspan="3" colspan="2" class="kuan-dai"> ',
            '<div class="progress-label">上行宽度速率 ' + itemArr[0].up + '</div>',
            '<div style="width:180px;height:15px;"> ',
            '<div class="progress" style="float:left;height:8px;width:180px;background-color:#383E60;">',
            '<div class="progress-bar progress-bar-striped" style="min-width:0;width:' + itemArr[0].up.replace("Mbps", "") + '%"></div>',
            '</div>',
            '</div> ',
            '<div class="progress-label">下行宽度速率 ' + itemArr[0].down + '</div>',
            '<div style="width:180px;height:15px;">',
            '<div class="progress" style="float:left;height:8px;width:180px;background-color:#383E60;">',
            '<div class="progress-bar progress-bar-striped" style="min-width:0;width:' + itemArr[0].down.replace("Mbps", "") + '%"></div>',
            '</div>',
            '</div>',
            '</td>',
            '</tr>',
            '<tr>',
            '<td class="label-name score">' + itemArr[0].score + '分</td>',
            '</tr>',
            '<tr>',
            '<td class="label-name"><div class="os-name" title="' + (itemArr[0].osName || "--") + '">' + (itemArr[0].osName || "--") + '</div></td>',
            '</tr>',
            '<tr class="device-use">',
            '<td></td>',
            '<td><div class="nei-cun-size"><span>' + (itemArr[0].memory || 0) + '</span></div></td>',
            '<td><div class="cpu-use"><span>' + itemArr[0].cpuUsageAvg + '</span></div></td>',
            '<td><div class="nei-cun-use"><span>' + itemArr[0].memUsageAvg + '</span></div></td>',
            '</tr>',
            '<tr>',
            '<td></td>',
            '<td><div class="labe-value">内存大小</div></td>',
            '<td><div class="labe-value">cpu占用率</div></td>',
            '<td><div class="labe-value">内存使用率</div></td>',
            '</tr>'
        ];
        var tr2 = [];
        if (itemArr.length > 1) {
            itemArr[1].up = itemArr[1].up || "--";
            itemArr[1].down = itemArr[1].down || "--";
            var gradeImg = "";
            if (1 == itemArr[1].healthGrade) {
                gradeImg = "device-green.png";
            } else if (2 == itemArr[1].healthGrade) {
                gradeImg = "device-red.png";
            } else {
                gradeImg = "device-gray.png";
            }
            tr2 = [
                '<tr><td colspan="4"><div class="split-line"></div></td></tr>',
                '<tr> ',
                '<td rowspan="3" class="device-img">',
                '<img src="../static/images/' + gradeImg + '"/>',
                '</td> ',
                '<td><div class="label-name">台席分数</div></td> ',
                '<td rowspan="3" colspan="2" class="kuan-dai"> ',
                '<div class="progress-label">上行宽度速率 ' + itemArr[1].up + '</div>',
                '<div style="width:180px;height:15px;"> ',
                '<div class="progress" style="float:left;height:8px;width:180px;background-color:#383E60;">',
                '<div class="progress-bar progress-bar-striped" style="min-width:0;width:' + itemArr[1].up.replace("Mbps", "") + '%"></div>',
                '</div>',
                '</div> ',
                '<div class="progress-label">下行宽度速率 ' + itemArr[1].down + '</div>',
                '<div style="width:180px;height:15px;">',
                '<div class="progress" style="float:left;height:8px;width:180px;background-color:#383E60;">',
                '<div class="progress-bar progress-bar-striped" style="min-width:0;width:' + itemArr[1].down.replace("Mbps", "") + '%"></div>',
                '</div>',
                '</div>',
                '</td>',
                '</tr>',
                '<tr>',
                '<td class="label-name score">' + itemArr[1].score + '分</td>',
                '</tr>',
                '<tr>',
                '<td class="label-name"><div class="os-name" title="' + (itemArr[0].osName || "--") + '">' + (itemArr[0].osName || "--") + '</div></td>',
                '</tr>',
                '<tr class="device-use">',
                '<td></td>',
                '<td><div class="nei-cun-size"><span>' + (itemArr[1].memory || 0) + '</span></div></td>',
                '<td><div class="cpu-use"><span>' + itemArr[1].cpuUsageAvg + '</span></div></td>',
                '<td><div class="nei-cun-use"><span>' + itemArr[1].memUsageAvg + '</span></div></td>',
                '</tr>',
                '<tr>',
                '<td></td>',
                '<td><div class="labe-value">内存大小</div></td>',
                '<td><div class="labe-value">cpu占用率</div></td>',
                '<td><div class="labe-value">内存使用率</div></td>',
                '</tr>'
            ]
        }
        var deviceHtml = [
            '<div class="swiper-slide">',
            '<table>',
            tr1.join(""),
            tr2.join(""),
            '</table>',
            '</div> '
        ];
        html.push(deviceHtml.join(""));
    }
    $("#device-info").html("");
    if (html.length > 0) {
        var dataHtml = "<div class='swiper-container visual_swiper_deviceInfo'><div class='swiper-wrapper'>" + html.join("") + "</div>"
        $("#device-info").html(dataHtml);
        var mySwiper1 = new Swiper('.visual_swiper_deviceInfo', {
            autoplay: true,//可选选项，自动滑动
            speed: 1500,//可选选项，滑动速度
            autoplay: {
                delay: 15000,//毫秒
            }
        });
    } else {
        noDataTip($("#device-info"));
    }
}

//学生使用材料列表
function loadStudentsList(data) {
    console.log(data)
    var option = {
        tooltip: {trigger: 'axis',},
        grid: {left: '0%', bottom: '10%'},
        legend: {
            icon: 'rect',
            itemWidth: 10, itemHeight: 10, itemGap: 10,
            data: data.legendArr,
            right: '10px', top: '10px',
            textStyle: {fontSize: 12, color: '#fff'}
        },
        xAxis: [
            {
                type: 'category',
                axisLine: {lineStyle: {color: '#57617B'}}, axisLabel: {interval: 0, textStyle: {color: '#fff',}},
                data: data.categoryArr
            }
        ],
        yAxis: [{
            type: 'value',
            axisTick: {
                show: false
            },
            axisLine: {lineStyle: {color: '#57617B'}},
            axisLabel: {margin: 10, textStyle: {fontSize: 12}, textStyle: {color: '#fff'}, formatter: '{value}'},
            splitLine: {
                show: true,
                lineStyle: {
                    type: 'dashed',
                    color: ['#25CEF3']
                }
            }

        }],
        series: [
            {
                name: '泥条',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#0c79cc"
                        }, {
                            offset: 0.8,
                            color: "#28a0f7"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [356, 689, 1520, 1340, 2368, 1980]
            },
            {
                name: '火箭',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#12ac76"
                        }, {
                            offset: 0.8,
                            color: "#47cca1"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '薄荷树',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#1e3db1"
                        }, {
                            offset: 0.8,
                            color: "#275ffc"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '蛋糕胚',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#413cf1"
                        }, {
                            offset: 0.8,
                            color: "#5c5dff"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '冰淇淋',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#f2902d"
                        }, {
                            offset: 0.8,
                            color: "#f9ce68"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '铅笔',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#b54b55"
                        }, {
                            offset: 0.8,
                            color: "#f76d6a"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [450, 869, 1320, 1248, 368, 980]
            }
        ]
    };
    var myChart = echarts.init(document.getElementById('material-students-list'));
    myChart.clear();
    if (data.channelTime.length > 0) {
        myChart.setOption(option);
    } else {
        noDataTip($("#material-students-list"));
    }

}
// 材料使用对比
function loadMaterialContrast(data) {
    console.log(data)
    var option = {
        tooltip: {trigger: 'axis',},
        grid: {left: '8%', right: '0%', bottom: '10%'},
        legend: {
            icon: 'rect',
            itemWidth: 10, itemHeight: 10, itemGap: 10,
            data: data.legendArr,
            right: '10px', top: '10px',
            textStyle: {fontSize: 12, color: '#fff'}
        },
        xAxis: [
            {
                type: 'category',
                axisLine: {lineStyle: {color: '#57617B'}}, axisLabel: {interval: 0, textStyle: {color: '#fff',}},
                data: data.categoryArr
            }
        ],
        yAxis: [{
            type: 'value',
            axisTick: {
                show: false
            },
            axisLine: {lineStyle: {color: '#57617B'}},
            axisLabel: {margin: 10, textStyle: {fontSize: 12}, textStyle: {color: '#fff'}, formatter: '{value}'},
            splitLine: {
                show: true,
                lineStyle: {
                    type: 'dashed',
                    color: ['#25CEF3']
                }
            }

        }],
        series: [
            {
                name: '泥条',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#0c79cc"
                        }, {
                            offset: 0.8,
                            color: "#28a0f7"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [356, 689, 1520, 1340, 2368, 1980]
            },
            {
                name: '火箭',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#12ac76"
                        }, {
                            offset: 0.8,
                            color: "#47cca1"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '薄荷树',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#1e3db1"
                        }, {
                            offset: 0.8,
                            color: "#275ffc"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '蛋糕胚',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#413cf1"
                        }, {
                            offset: 0.8,
                            color: "#5c5dff"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '冰淇淋',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#f2902d"
                        }, {
                            offset: 0.8,
                            color: "#f9ce68"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [1345, 969, 520, 1348, 1368, 2980]
            },
            {
                name: '铅笔',
                type: 'bar',
                barWidth: 10,
                barGap: '50%',
                itemStyle: {
                    normal: {
                        // barBorderRadius:[10, 10, 0, 0],
                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                            offset: 0,
                            color: "#b54b55"
                        }, {
                            offset: 0.8,
                            color: "#f76d6a"
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                    }
                },
                data: [450, 869, 1320, 1248, 368, 980]
            }
        ]
    };
    var myChart = echarts.init(document.getElementById('material-students-use-contrast'));
    myChart.clear();
    if (data.channelTime.length > 0) {
        myChart.setOption(option);
    } else {
        noDataTip($("#material-students-use-contrast"));
    }

}
//班级材料使用情况统计表
function loadClassMaterialSituation(data) {
    //主要传染病
    var histogramChart1 = echarts.init(document.getElementById('class-material-situation'));
    histogramChart1.setOption({

        color: ['#0178de', '#31a0f9'],
        grid: {
            left: '5%',
            right: '5%',
            bottom: '5%',
            containLabel: true
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a}<br/>{b}<br/>{c}人"
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                data: data.categoryArr,
                axisLine: {
                    lineStyle: {
                        color: '#5bc0de'
                    },
                },
                axisLabel: {
                    interval: 0,
                    rotate: 40,
                    textStyle: {
                        color: '#fff'
                    }
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLine: {
                    lineStyle: {
                        color: '#5bc0de'
                    },
                },
                splitLine: {
                    "show": false
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function (value) {
                        return value + ""
                    },
                },
            }
        ],
        series: [
            {
                name: '材料使用情况',
                type: 'bar',
                barWidth: 20,
                data: data.provinceTime,
            },
        ]
    })
}

//既定时间材料选用
function loadUseMaterialTime(data) {
    var myChart = echarts.init(document.getElementById('student-use-material-time'));
    myChart.clear();
    option = {
        title: {
            text: ''
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: data.legendArr,
            textStyle: {
                color: '#fff'
            },
            top: '8%',
            right: '5px'
        },
        grid: {
            top: '40%',
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        color: ['#FF4949', '#FFA74D', '#FFEA51', '#4BF0FF', '#44AFF0', '#4E82FF', '#584BFF', '#BE4DFF', '#F845F1'],
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: data.provinceTime,
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            }
        },
        yAxis: {
            name: '',
            type: 'value',
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            data: data.channelTime,
        },
        series: [
            {
                name: '泥条',
                type: 'line',
                data: [520, 423.63, 183.14, 633.01, 704.47, 520, 423.63, 183.14, 633.01, 704.47]
            },
            {
                name: '火箭',
                type: 'line',
                data: [374.76, 364.76, 274.76, 371.82, 1259.87, 374.76, 364.76, 274.76, 371.82, 1259.87]
            },
            {
                name: '薄荷树',
                type: 'line',
                data: [144.77, 125.17, 1113.17, 1254.56, 185.84, 374.76, 364.76, 274.76, 371.82, 1259.87]
            },
            {
                name: '蛋糕胚',
                type: 'line',
                data: [686.17, 847.26, 895.22, 865.28, 886.72, 144.77, 125.17, 1113.17, 1254.56]
            },
            {
                name: '冰淇淋',
                type: 'line',
                data: [633.47, 577.89, 709.56, 821.48, 1294.59, 686.17, 847.26, 895.22, 865.28, 886.72]
            }
        ]
    };
    myChart.setOption(option);
}

//账户余额
function loadAccountBalance(data) {
    var myChart = echarts.init(document.getElementById('account-balance'));
    myChart.clear();
    option = {
        title: {
            text: ''
        },
        tooltip: {
            trigger: 'axis'
        },
        // legend: {
        //     data:data.legendArr,
        //     textStyle:{
        //         color: '#fff'
        //     },
        //     top: '8%',
        //     right:'5px'
        // },
        // grid: {
        //     top: '40%',
        //     left: '3%',
        //     right: '4%',
        //     bottom: '3%',
        //     containLabel: true
        // },
        color: ['#FF4949', '#FFA74D', '#FFEA51', '#4BF0FF', '#44AFF0', '#4E82FF', '#584BFF', '#BE4DFF', '#F845F1'],
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: data.provinceTime,
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            }
        },
        yAxis: {
            name: '',
            type: 'value',
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            data: data.channelTime,
        },
        series: [
            {
                name: '金玲',
                type: 'line',
                data: [520, 423.63, 183.14, 633.01, 704.47, 520, 423.63, 183.14, 633.01, 704.47]
            }
        ]
    };
    myChart.setOption(option);
}

// 材料选用的单一与多样
//既定时间材料选用
function loadUseMaterialWays(data) {
    var myChart = echarts.init(document.getElementById('use-material-ways'));
    myChart.clear();
    option = {
        title: {
            text: ''
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: data.legendArr,
            textStyle: {
                color: '#fff'
            },
            top: '8%',
            right: '5px'
        },
        grid: {
            top: '40%',
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        color: ['#FF4949', '#FFA74D', '#FFEA51', '#4BF0FF', '#44AFF0', '#4E82FF', '#584BFF', '#BE4DFF', '#F845F1'],
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: data.provinceTime,
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            }
        },
        yAxis: {
            name: '',
            type: 'value',
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#fff'
                }
            },
            data: data.channelTime,
        },
        series: [
            {
                name: '泥条',
                type: 'line',
                data: [520, 423.63, 183.14, 633.01, 704.47, 520, 423.63, 183.14, 633.01, 704.47]
            },
            {
                name: '火箭',
                type: 'line',
                data: [374.76, 364.76, 274.76, 371.82, 1259.87, 374.76, 364.76, 274.76, 371.82, 1259.87]
            },
            {
                name: '薄荷树',
                type: 'line',
                data: [144.77, 125.17, 1113.17, 1254.56, 185.84, 374.76, 364.76, 274.76, 371.82, 1259.87]
            },
            {
                name: '蛋糕胚',
                type: 'line',
                data: [686.17, 847.26, 895.22, 865.28, 886.72, 144.77, 125.17, 1113.17, 1254.56]
            },
            {
                name: '冰淇淋',
                type: 'line',
                data: [633.47, 577.89, 709.56, 821.48, 1294.59, 686.17, 847.26, 895.22, 865.28, 886.72]
            }
        ]
    };
    myChart.setOption(option);
}

// 小一班所有学生使用材料情况
//班级材料使用情况统计表
function loadMaterialUseSituationClassOne(data) {
    //主要传染病
    var histogramChart1 = echarts.init(document.getElementById('class-one-material-use-situation'));
    histogramChart1.setOption({

        color: ['#ffb318', '#ffdd90'],
        grid: {
            left: '5%',
            right: '5%',
            bottom: '5%',
            containLabel: true
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a}<br/>{b}<br/>{c}人"
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                data: data.categoryArr,
                axisLine: {
                    lineStyle: {
                        color: '#5bc0de'
                    },
                },
                axisLabel: {
                    interval: 0,
                    rotate: 40,
                    textStyle: {
                        color: '#fff'
                    }
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLine: {
                    lineStyle: {
                        color: '#5bc0de'
                    },
                },
                splitLine: {
                    "show": false
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function (value) {
                        return value + ""
                    },
                },
            }
        ],
        series: [
            {
                name: '材料使用情况',
                type: 'bar',
                barWidth: 20,
                data: data.provinceTime,
            },
        ]
    })
}

//班级材料未使用情况统计表
function loadMaterialUnUseSituationClassOne(data) {
    //主要传染病
    var histogramChart1 = echarts.init(document.getElementById('class-one-material-unuse-situation'));
    histogramChart1.setOption({

        color: ['#00d887', '#51e4ad'],
        grid: {
            left: '5%',
            right: '5%',
            bottom: '5%',
            containLabel: true
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a}<br/>{b}<br/>{c}人"
        },
        calculable: true,
        xAxis: [
            {
                type: 'category',
                data: data.categoryArr,
                axisLine: {
                    lineStyle: {
                        color: '#5bc0de'
                    },
                },
                axisLabel: {
                    interval: 0,
                    rotate: 40,
                    textStyle: {
                        color: '#fff'
                    }
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLine: {
                    lineStyle: {
                        color: '#5bc0de'
                    },
                },
                splitLine: {
                    "show": false
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function (value) {
                        return value + ""
                    },
                },
            }
        ],
        series: [
            {
                name: '材料使用情况',
                type: 'bar',
                barWidth: 20,
                data: data.provinceTime,
            },
        ]
    })
}

function loadMaterialUseSituationClassOnePie(data) {
    var pie_age = echarts.init(document.getElementById("class-one-material-use-situation-circle"), 'infographic');
//var pie_age =echarts.init(document.getElementById("pie_age"),'shine'); 
    option = {
        title: {
            x: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: data.categoryArr,
            textStyle: {color: '#fff'}
        },

        label: {
            normal: {
                textStyle: {
                    color: 'red'  // 改变标示文字的颜色
                }
            }
        },
        series: [
            {
                name: '小一班所有学生使用材料情况',
                type: 'pie',
                radius: ['30%', '55%'],
                center: ['50%', '60%'],
                data: data.provinceTime,

                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,

                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }

            }
        ]
    };
    pie_age.setOption(option);
}

//初始化基础信息
function initBaseInfo() {
    //初始化日期
    /*$("#data-date").my97({
       dateFmt:'yyyyMMdd',
       minDate:"%y-{%M}-{%d-30}",
       maxDate:"%y-%M-{%d}",
       startDate: [{
           doubleCalendar: false,
           isShowWeek: false,
           isShowClear: false,
           readOnly: true
       }],
       onpicked:function(dp){
           g_dataDate=$('#data-date').val();
           $("#query-page-data").trigger("click");
       }
   });*/
    var dataDate = "2019年12月31日";
    $("#td-data-date").text(dataDate);


    $(".cust-type-default").on("click", function () {
        $(this).addClass("active").siblings().removeClass("active");
        $("#query-page-data").trigger("click");
    });

}

//获取渠道参数
function getGroupChannelParam() {
    var areaCode = "";
    try {
        var cityId = $('#selectCity').combobox("getValue");
        var countyId = $('#selectCounty').combobox("getValue");
        if ("" == areaCode && "" != countyId) {
            areaCode = countyId;
        } else if ("" == areaCode && "" != cityId) {
            areaCode = cityId;
        }
    } catch (e) {
    }
    var channelName = $.trim($("#channel_name").val());
    var channelParam = {'areaCode': areaCode, "channelName": channelName};
    return channelParam;
}


function noDataTip($selector) {
    var currModH = $selector.height();
    var top = currModH > 180 ? "35%" : "13%";
    var $li = [
        "<div class='no-data' style='width:90%;position: absolute;top:" + top + ";text-align:center;color:#a59999;'>",
        "<img src='../static/images/no-data.png' style='width:200px;height:200px;'/>",
        "<div style='font-size:16px;opacity:0.7;color:#fff;'>暂无数据</div>",
        "</div>"
    ]
    $selector.append($li.join(""));
}

function keepTwoDecimal(currVal) {
    var result = parseFloat(currVal);
    if (isNaN(result)) {
        return false;
    }
    result = Math.round(currVal * 100) / 100;
    return result;
}

//初始化页面
function loadPageData() {
    //获取渠道信息
    var groupChannelInfo = g_channelInfo;
    //第一步：优先判断url请求参数里面
    // let param=JSON.parse(gDataGather.param);
    // if(Object.keys(param).length>0){
    //  groupChannelInfo=param;
    //  gDataGather.param="{}";
    // }
    if (Object.keys(groupChannelInfo).length == 0) {
        groupChannelInfo = window.localStorage.getItem("group-channel-info");
        if (undefined == groupChannelInfo || null == groupChannelInfo) {
            groupChannelInfo = {
                "channelCode": "11228790",
                "groupChannelCode": "3201001965930",
                "channelName": "中国电信南京分公司@玄武大钟亭营业厅"
            };
        } else {
            groupChannelInfo = JSON.parse(groupChannelInfo);
        }
    } else {
        window.localStorage.setItem("group-channel-info", JSON.stringify(groupChannelInfo));
    }
    //开始动画特效
    $('#load').show();
    $('#load').fadeOut(500, function () {
    });

    //引入office_efficiency_data.js缓存假数据
    if (data.code == 0) {
        $(".no-data").remove();
        //学生使用材料列表
        loadStudentsList(data.materialStudentsList);
        // 加载班级材料使用情况统计报表
        loadClassMaterialSituation(data.classMaterialSituation);
        //既定时间材料选用
        loadUseMaterialTime(data.useMaterialTime);
        // 加载账户余额折线图
        loadAccountBalance(data.accountBalance);
        //加载门店台席健康度详情
        loadChannelDeviceDetail(data.channelDeviceInfo);
        //材料选用的单一与多样
        loadUseMaterialWays(data.useMaterialWays);
        // 小一班所有学生使用材料情况
        loadMaterialUseSituationClassOne(data.classOneMaterialUseSituation);
        // 小一班所有学生未使用材料情况
        loadMaterialUnUseSituationClassOne(data.classOneMaterialUseSituation);
        loadMaterialUseSituationClassOnePie(data.classOneMaterialUseSituationPie);
        // 材料使用对比
        loadMaterialContrast(data.materialStudentsList);

    }

}

$(function () {
    //加载基础信息
    initBaseInfo();
    //加载页面数据
    loadPageData();
})